home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / clipGraphEditor.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.9 KB  |  353 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  01/07/2000
  22. // Author:         zguo
  23. //
  24. //  Procedure Name:
  25. //        clipGraphEditor
  26. //
  27. //  Description:
  28. //        Open the graph editor for the anim curves of the selected clips
  29. //        in the clipEditor.
  30. //
  31. //  Input Arguments:
  32. //      $editor - The Trax Editor.
  33. //
  34. //  Return Value:
  35. //      None.
  36. //
  37.  
  38. proc string[] clipGraphEdSelectClips( string $editor )
  39. {
  40.     string $clipNameList[];
  41.  
  42.     // Get clip index and scheduler from the clipEditor.
  43.     //
  44.     string $clips[] = `clipEditor -q -sc $editor`;
  45.     int $numClips = size( $clips );
  46.  
  47.     // If no clip was selected, return. If there is one clip selected,
  48.     // clipEditor returns two strings: schedulerName and clip index.
  49.     //
  50.     if( $numClips <= 1 )
  51.         return $clipNameList;
  52.  
  53.     int $sInd = 0;
  54.     int $cInd = 0;
  55.     int $clipIndices[];
  56.     string $scheduler[];
  57.     for( $i = 0; $i < $numClips; $i +=2 )
  58.     {
  59.         $scheduler[$sInd] = $clips[$i];
  60.         $clipIndices[$cInd] = $clips[$i + 1];
  61.  
  62.         $sInd ++;
  63.         $cInd ++;
  64.     }
  65.  
  66.     // Get clip names from their index.
  67.     //
  68.     int $numIndices = size( $clipIndices );
  69.     for( $i = 0; $i < $numIndices; $i ++ )
  70.     {
  71.         $clipNameList[$i] = 
  72.             `clipSchedule -ci $clipIndices[$i] -q -n $scheduler[$i]`;
  73.     }
  74.  
  75.     return $clipNameList;
  76. }
  77.  
  78.  
  79. proc string[] clipGraphEdSelectBlends( string $editor )
  80. {
  81.     string $blendNodeList[];
  82.  
  83.     // Get blends index and scheduler from the clipEditor.
  84.     //
  85.     string $blends[] = `clipEditor -q -sb $editor`;
  86.     int $numBlends = size( $blends );
  87.  
  88.     // If no blend was selected, return. If there is one blend selected,
  89.     // clipEditor returns three strings: schedulerName and two clip indices.
  90.     //
  91.     if( $numBlends <= 2 )
  92.         return $blendNodeList;
  93.  
  94.     int $sInd = 0;
  95.     int $bInd1 = 0;
  96.     int $bInd2 = 0;
  97.     int $bInds1[];
  98.     int $bInds2[];
  99.     string $schs[];
  100.     for( $i = 0; $i < $numBlends; $i +=3 )
  101.     {
  102.         $schs[$sInd] = $blends[$i];
  103.         $bInds1[$bInd1] = $blends[$i + 1];
  104.         $bInds2[$bInd2] = $blends[$i + 2];
  105.  
  106.         $sInd ++;
  107.         $bInd1 ++;
  108.         $bInd2 ++;
  109.     }
  110.  
  111.     // Get clip names from their index.
  112.     //
  113.     int $bIndex = 0;
  114.     string $bName[];
  115.     int $numIndices = size( $bInds1 );
  116.     for( $i = 0; $i < $numIndices; $i ++ )
  117.     {
  118.         $bName = `clipSchedule -bn $bInds1[$i] $bInds2[$i] -q -n $schs[$i]`;
  119.         int $nBlends = `size($bName)`;
  120.         for ($jj = 0; $jj < $nBlends; $jj++) {
  121.             $blendNodeList[$bIndex++] = $bName[$jj];
  122.         }
  123.     }
  124.  
  125.     return $blendNodeList;
  126. }
  127.  
  128. proc int isVisible(string $graphEd, int $forceOpen) 
  129. //
  130. //    Description:
  131. //        Returns 1 if the specified graphEditor is visible, otherwise
  132. //        0 is returned. 
  133. //        If the editor is in the main window, but the main window is 
  134. //        minimized, the editor is not considered visible. If the editor
  135. //        is in its own window and that window is minimized, the editor 
  136. //        is considered visible.
  137. //
  138. //        If the $forceOpen argument is used, if a main Maya window is 
  139. //        found and it is iconified, it is expanded.
  140. //
  141. {
  142.     string $parentLayout = `editor -q -p $graphEd`;
  143.     if (`size($parentLayout)` == 0) {
  144.         return false;
  145.     }
  146.  
  147.     string $buff[];
  148.     tokenize($parentLayout, "|", $buff);
  149.  
  150.     //    The main Maya window is a special case.
  151.     if (`window -q -mw $buff[0]`) {
  152.         if (`window -q -i $buff[0]`) {
  153.             if ($forceOpen) {
  154.                 showWindow $buff[0];
  155.             } else {
  156.                 //    No editors are visible in the main window.
  157.                 //
  158.                 return false;
  159.             }
  160.         }
  161.  
  162.         string $visiblePanels[] = `getPanel -vis`;
  163.         string $graphEdPanel = `editor -q -panel $graphEd`;
  164.  
  165.         string $visItem;
  166.         int $found = false;
  167.  
  168.         for ($visItem in $visiblePanels) {
  169.             if ($visItem == $graphEdPanel) {
  170.                 $found = true;
  171.                 break;
  172.             }
  173.         }
  174.  
  175.         return $found;
  176.     }
  177.  
  178.     return true;
  179. }
  180.  
  181. proc string availibleGraphEditor(int $forceOpen)
  182. //
  183. //    Description:
  184. //        Returns an avalible Graph Editor. This procedure assumes that the
  185. //        Graph Editor names are in the form of graphEditor#GraphEd, 
  186. //        which is their default. 
  187. //
  188. //        If a Graph Editor is not found, "" is returned.
  189. //
  190. //        If a Graph Editor is set to not Auto Load selected objects
  191. //        it is considered unavalible.
  192. //
  193. {
  194.     string $regexp = "graphEditor[0-9]*GraphEd$";
  195.     string $item;
  196.     string $searchResultList[];
  197.  
  198.     int $nMatch = 0;
  199.     string $editors[] = `lsUI -ed`;
  200.     string $sorted[] = `sort($editors)`;
  201.     for ($item in $sorted) {
  202.         string $searchResult = match($regexp, $item);
  203.         if( $searchResult == $item) {
  204.             $searchResultList[$nMatch++] = $searchResult;
  205.         }
  206.     }
  207.  
  208.     if ($nMatch == 0) {
  209.         return "";
  210.     }
  211.  
  212.     //    Get rid of all of the editors that are not currently displayed.
  213.     //
  214.     int $i;
  215.     int $nEditors = 0;
  216.     string $graphEditorList[];
  217.     string $candidateGraphEditor;
  218.     for ($i = 0; $i < $nMatch; $i++) {
  219.         //    Only editors that are created should be considered.
  220.         //
  221.         if (isVisible($searchResultList[$i], $forceOpen)) {
  222.             //    Avoid the ones with auto load off.
  223.             //
  224.             string $mlc = `editor -q -mlc $searchResultList[$i]`;
  225.             string $outline = `selectionConnection -q -p $mlc`;
  226.             if (isAutoLoad($outline)) {
  227.                 $graphEditorList[$nEditors++] = $searchResultList[$i];
  228.  
  229.                 //    Only one Graph Editor is needed.
  230.                 break;
  231.             } else {
  232.                 if (`size($candidateGraphEditor)` == 0) {
  233.                     $candidateGraphEditor = $searchResultList[$i];
  234.                 }
  235.             }
  236.         }
  237.     }
  238.  
  239.     string $graphEditor = "";
  240.     if (size($graphEditorList) == 0) {
  241.         if (size($candidateGraphEditor) == 0) {
  242.             $graphEditor = "";
  243.         } else {
  244.             $graphEditor = $candidateGraphEditor;
  245.         }
  246.     } else {
  247.         $graphEditor = $graphEditorList[0];
  248.     }
  249.  
  250.     if (!$forceOpen && size($graphEditor) == 0) {
  251.         //    Check one more time, this time if the main Maya window is 
  252.         //    encountered and it is iconified, force it open.
  253.         //
  254.         $graphEditor = availibleGraphEditor(true);
  255.     }
  256.  
  257.     //    Return the graphEditor, if it was found.
  258.     //
  259.     return $graphEditor;
  260. }
  261.  
  262.  
  263. global proc clipGraphEditor( string $editor )
  264. {
  265.     //    1. Find an avalible editor, if one does not exist, create one.
  266.     //    2. Get the clips to display.
  267.     //    3. Get the blends to display.
  268.     //    4. If window is minimized, expand
  269.     //    5. Change the selected items in the outliner
  270.     //    6. Change the selected items in the editor.
  271.     //    7. Frame the view.
  272.  
  273.     //    Get the clips selected in the Trax Editor.
  274.     //
  275.     string $clipNodeList[] = clipGraphEdSelectClips($editor);
  276.  
  277.     //    Get the blends selected in the Trax Editor.
  278.     //
  279.     string $blendNodeList[] = clipGraphEdSelectBlends($editor);
  280.  
  281.     //    Get a Graph Editor and the Graph Editor Outline
  282.     //
  283.     string $graphEditor = availibleGraphEditor(false);
  284.     if (`size($graphEditor)` == 0) {
  285.         GraphEditor;
  286.         $graphEditor = availibleGraphEditor(false);
  287.  
  288.         if (`size($graphEditor)` == 0) {
  289.             error("Could not get the Graph Editor.");
  290.         }
  291.     }
  292.  
  293.     string $editorMLC = `editor -q -mlc $graphEditor`;
  294.     string $graphEditorOutliner = `selectionConnection -q -p $editorMLC`;
  295.  
  296.     //    If the Graph Editor is iconified, expand it.
  297.     //
  298.     string $parentLayout = `editor -q -p $graphEditor`;
  299.     string $buff[];
  300.     tokenize($parentLayout, "|", $buff);
  301.  
  302.     //    If this is not the main window, bring it to the front.
  303.     //
  304.     if (!`window -q -mw $buff[0]`) {
  305.         showWindow $buff[0];
  306.     } 
  307.  
  308.     int $nClips = `size($clipNodeList)`;
  309.     int $nBlends = `size($blendNodeList)`;
  310.     int $nSelected = $nClips + $nBlends;
  311.     if ($nSelected > 0) {
  312.         //    Clear the selection list.
  313.         //
  314.         select -cl;
  315.  
  316.         //    Add the selected blends and display in the editor.
  317.         //
  318.         for ($i = 0; $i < $nBlends; $i++) {
  319.             select -add $blendNodeList[$i];
  320.         }
  321.  
  322.         //    Add the selected clips and display in the editor.
  323.         //
  324.         for ($i = 0; $i < $nClips; $i++) {
  325.             select -add $clipNodeList[$i];
  326.         }
  327.     }
  328.  
  329.     //    Update the Graph Editor and Graph Editor Outliner.
  330.     //
  331.     if (!isAutoLoad($graphEditorOutliner)) {
  332.         doReload($graphEditorOutliner);
  333.     }
  334.  
  335.     int $editorLocked = `selectionConnection -query -lock $editorMLC`;
  336.     if ($editorLocked) {
  337.         editor -edit -unlockMainConnection $graphEditor;
  338.     }
  339.  
  340.     editor -edit -mlc animationList $graphEditor;
  341.  
  342.     //    Frame the view.
  343.     //
  344.     animCurveEditor -e -la "selected" $graphEditor;
  345.  
  346.     //    Restore the mainListConnection to the graph editor.
  347.     //
  348.     editor -edit -mlc $editorMLC $graphEditor;
  349.     if ($editorLocked) {
  350.         editor -edit -lockMainConnection $graphEditor;
  351.     }
  352. }
  353.